package com.lin.learning.questionmanagement.controller;

import com.lin.learning.questionmanagement.dto.AddTeacherDto;
import com.lin.learning.questionmanagement.dto.UpdateTeacherDto;
import com.lin.learning.questionmanagement.service.TeacherService;
import com.our.learning.infrastructure.pojo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;


@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private final TeacherService teacherService;

    public TeacherController(TeacherService teacherService) {
        this.teacherService = teacherService;
    }

    @PostMapping
    public ResponseResult addTeacher(@RequestBody AddTeacherDto addTeacherDto){
        return teacherService.addTeacher(addTeacherDto);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteTeacher(@PathVariable Integer id){
        return teacherService.deleteTeacher(id);
    }

    @PutMapping
    public ResponseResult updateTeacher(@RequestBody UpdateTeacherDto updateTeacherDto){
        return teacherService.updateTeacher(updateTeacherDto);
    }

    @GetMapping("/byid/{id}")
    public ResponseResult getTeacherById(@PathVariable Integer id){
        return teacherService.getTeacherById(id);
    }

    @GetMapping("/byname")
    public ResponseResult getTeacherByName(@PathParam("name") String name){
        return teacherService.getTeacherByName(name);
    }
}
